//
//  GYVerGoodsCell.m
//  GoodLuck
//
//  Created by apple on 2018/3/7.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYVerGoodsCell.h"
#import "GYNetWorkTools.h"

@interface GYVerGoodsCell ()

@property (weak, nonatomic) IBOutlet UIImageView *good_imageView;
@property (weak, nonatomic) IBOutlet UILabel *good_titleLbale;
@property (weak, nonatomic) IBOutlet UILabel *good_priceLable;
@property (weak, nonatomic) IBOutlet UILabel *good_saluemLable;


@property (weak, nonatomic) IBOutlet UIView *storeInfoView;

@property (weak, nonatomic) IBOutlet UILabel *storeNameLbale;
@property (weak, nonatomic) IBOutlet UILabel *storeDesLable;
@property (weak, nonatomic) IBOutlet UILabel *storeServiceLable;
@property (weak, nonatomic) IBOutlet UILabel *storeDeliverLable;

/** 缓存店铺评分 */
@property (nonatomic, strong) NSDictionary *cachesStoreScoreInfoDic;
@end
@implementation GYVerGoodsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.storeInfoView.hidden = YES;
}

//店铺评分信息
- (IBAction)onClick:(UIButton *)sender {
    self.storeInfoView.hidden = NO;
    if (self.cachesStoreScoreInfoDic != nil) {
        [self jsonStoreInfo:self.cachesStoreScoreInfoDic];
    }else {
        //加载店铺评分
        [EasyLodingView showLodingText:@"正在加载..."];
        [GYNetWorkTools requestStoreScoreInfo:self.model.store_id success:^(NSDictionary *obj) {
            int code = [[obj objectForKey:@"code"] intValue];
            NSDictionary *datas = [obj objectForKey:@"datas"];
            if (code == 200) {
                [EasyLodingView hidenLoding];
                NSDictionary *store_credit = [datas objectForKey:@"store_credit"];
                self.cachesStoreScoreInfoDic = store_credit;
                [self jsonStoreInfo:store_credit];
            }else {
                [EasyTextView showText:@"加载出错,请重新加载!"];
                [EasyLodingView hidenLoding];
                NSLog(@"网络加载出错...%@",[datas objectForKey:@"error"]);
            }
        } error:^(NSError *error) {
            [EasyTextView showText:@"加载出错,请重新加载!"];
            [EasyLodingView hidenLoding];
            NSLog(@"loadStoreScoreInfoFailed====%@",error);
        }];
    }

}

- (IBAction)storeInfoClick:(UIButton *)sender {
    switch (sender.tag) {
        case 1:
        {
            NSLog(@"跳转查看店铺信息...");
        }
            break;
            
        case 2:
        {
            self.storeInfoView.hidden = YES;
        }
            break;
            
        default:
            break;
    }
}


- (void)setModel:(GYSearchGoos *)model {
    _model = model;
    [self.good_imageView sd_setImageWithURL:[NSURL URLWithString:model.goods_image_url] placeholderImage:[UIImage imageNamed:@"4"]];
    self.good_titleLbale.text = model.goods_name;
    self.good_priceLable.text = [NSString stringWithFormat:@"¥%@",model.goods_price];
    self.good_saluemLable.text = [NSString stringWithFormat:@"销量 %@",model.goods_salenum];
}

- (CGFloat)cellHeight:(GYSearchGoos *)goods {
    self.model = goods;
    
    [self layoutIfNeeded];
    
    return CGRectGetMaxY(self.good_saluemLable.frame)+5;
}

/**
 解析店铺评分地址 并且赋值
 
 @param store_credit 店铺评分信息字典
 */
- (void)jsonStoreInfo:(NSDictionary *)store_credit {
    //店铺描述
    NSDictionary *store_desccredit = [store_credit objectForKey:@"store_desccredit"];
    self.storeDesLable.text = [NSString stringWithFormat:@"%@ %@",[store_desccredit objectForKey:@"text"],[store_desccredit objectForKey:@"credit"]];
    
    //服务态度
    NSDictionary *store_servicecredit = [store_credit objectForKey:@"store_servicecredit"];
    self.storeServiceLable.text = [NSString stringWithFormat:@"%@ %@",[store_servicecredit objectForKey:@"text"],[store_servicecredit objectForKey:@"credit"]];
    
    //发货速度
    NSDictionary *store_deliverycredit = [store_credit objectForKey:@"store_deliverycredit"];
    self.storeDeliverLable.text = [NSString stringWithFormat:@"%@ %@",[store_deliverycredit objectForKey:@"text"],[store_deliverycredit objectForKey:@"credit"]];
    
}

@end
